import {
  Center
} from '../center/center-model.js';
var center = new Center();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  bindGetUserInfo: function (e) {
    if (!e.detail.userInfo){
      return false;
    }
    var that = this;
    center._updateUserInfo(e.detail.userInfo, (data) => {
      if (data.user.status == 0) {
        wx.redirectTo({
          url: '/pages/home/forbidden',
        })
        return false;
      }
      wx.setStorageSync('userInfo', data.user);
      if (data.user) {
        that.setData({
          userInfo: data.user,
        })
      }
      let url = wx.getStorageSync('redirect-url');
      if(url){
        wx.redirectTo({
          url: url,  
        })
      }else{
        wx.switchTab({
          url: '/pages/home/home', 
        })
      }
    });
  },
})